﻿<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application.Lock();
        Application["sotruycap"] = 1;
        Application["soonline"] = 0;
        Application.UnLock();

    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started
        // Lưu trữ số ng online và truy cập
        string tt = Server.MapPath("~\\luutru.txt");
        if (System.IO.File.Exists(tt))
        {
            System.IO.StreamReader fs = new System.IO.StreamReader(tt);
            int so = int.Parse(fs.ReadToEnd());
            fs.Close();
            Application.Lock();
            Application["sotruycap"] = so + 1;
            Application["soonline"] = (int)Application["soonline"] + 1;
            Application.UnLock();
            // Ghi lại tập tin
            System.IO.StreamWriter sw = new System.IO.StreamWriter(tt);
            sw.Write(so + 1);
            sw.Close();
                 
        }

        Session["Madn"] = string.Empty;
        Session["GioHang"] = new List<MuaSanPham>();
        //Danh cho he Admin
        Session["tenND"] = string.Empty;
        Session["HoTenQT"] = string.Empty;
        Session["MaQT"] = 0;
        //Paypal
        Session["payment_amt"] = 0;
        //
        Session["username"] = string.Empty;
        Session["password"] = string.Empty;
        Session["App_Name"] = "MyNetwork Web Application!";
    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
